// NodePathUtilTest.ts
import { _decorator, Component, Node, log } from 'cc';
import { NodePathUtil } from '../../component/Utils/NodePathUtil';

const { ccclass } = _decorator;

@ccclass('NodePathUtilTest')
export class NodePathUtilTest extends Component {
    start() {
        const canvas = this.node.scene.getChildByName('Canvas');
        if (!canvas) {
            log('Canvas not found');
            return;
        }

        // 示例结构：Canvas/Main/Node
        const node = NodePathUtil.findByRootPath(canvas, '/Main/Node');
        if (node) {
            log('findByRootPath:', node.name);
            log('getPath:', NodePathUtil.getPath(node));
        } else {
            log('findByRootPath: not found');
        }

        const relativeTarget = NodePathUtil.findByRelativePath(
            this.node,
            '../../SomeNode',
        );
        if (relativeTarget) {
            log(
                'findByRelativePath:',
                NodePathUtil.getPath(relativeTarget),
            );
        } else {
            log('findByRelativePath: not found');
        }
    }
}
